package todo;

import done.*;

public class WashingController implements ButtonListener {	
	AbstractWashingMachine mach;
	WashingProgram currentProgram;
	TemperatureController tempController;
	WaterController waterController;
	SpinController spinController;
	boolean isStarted;
	double speed;
	
    public WashingController(AbstractWashingMachine theMachine, double theSpeed) {
		mach = theMachine;
		speed = theSpeed;
		tempController = new TemperatureController(mach, speed);
		waterController = new WaterController(mach, speed);
		spinController = new SpinController(mach, speed);
		tempController.start();
		waterController.start();
		spinController.start();
    }

    public void processButton(int theButton) {
    	if(currentProgram != null && (currentProgram.isInterrupted() || !currentProgram.isAlive())){
			currentProgram = null;
		}
    	
		switch(theButton){
		case 0: if(currentProgram != null){
			currentProgram.interrupt();
		}
		break;	
		case 1: if(currentProgram == null){
			currentProgram = new WashingProgram1(mach, speed, tempController, waterController, spinController);
			currentProgram.start();
		}	
		break;
		case 2: if(currentProgram == null){
			currentProgram = new WashingProgram2(mach, speed, tempController, waterController, spinController);
			currentProgram.start();
		}
		break;
		case 3: if(currentProgram == null){
			currentProgram = new WashingProgram3(mach, speed, tempController, waterController, spinController);
			currentProgram.start();
		}
		break;			
		}
    }
}
